package com.system.demo.entity.account;

import com.system.demo.entity.database.UserNotifications;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class NotificationMapper {

    // 格式化 LocalDateTime 的工具
    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 将 UserNotifications 转换为 NotificationVO
     */
    public static NotificationVO mapToNotificationVO(UserNotifications notification) {
        NotificationVO vo = new NotificationVO();
        vo.setContent(notification.getContent());
        vo.setStatus(notification.getStatus() == 1 ? "已读" : "未读");
        vo.setCreatedTime(formatLocalDateTime(notification.getCreatedTime()));
        return vo;
    }

    /**
     * 格式化 LocalDateTime
     */
    private static String formatLocalDateTime(LocalDateTime dateTime) {
        return dateTime != null ? dateTime.format(DATE_FORMATTER) : null;
    }
}
